package jianzhioffer.list;

import algorithm.model.ListNode;

/**
 * 反转链表
 * Created by yzy on 2020-05-28 19:29
 */
public class ReverseList {

    public static void main(String[] args) {
        ListNode nodes = ListNode.initDate(new int[]{1,2,3,4,5});
        System.out.println(reverseList(nodes));
    }

    public static ListNode reverseList(ListNode head) {
        ListNode result = null;
        ListNode dummy = null;
        while(head != null){
            dummy = head;       // 提取当前节点
            head = head.next;   // head后移

            dummy.next = result;
            result = dummy;

        }
        return result;
    }

}
